<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>React - Ajax</title>
    <script src="../build/react.js"></script>
    <script src="../build/react-dom.js"></script>
    <script src="../build/browser.min.js"></script>
    <script src="../build/jquery-1.10.1.min.js"></script>
</head>
<body>
    <div id="container"></div>
    <script type="text/babel">
        var UserGist = React.createClass({
            getInitialState: function(){
                return {
                    username: '',
                    lastGistUrl: ''
                }
            },
            componentDidMount: function(){
                $.get(this.props.source, function(result){
                    var lastGist = result[0];
                    if(this.isMounted()){
                        this.setState({
                            username: lastGist.login,
                            lastGistUrl: lastGist.html_url
                        });
                    }
                }.bind(this));
            },
            render: function(){
                return (
                        <div>
                            {this.state.username}`s last gist <a href={this.state.lastGistUrl}>here</a>
                        </div>
                );
            }
        });

        ReactDOM.render(
            <UserGist source="http://localhost:63342/cattle-react-demos/test/ajaxJson.json" />,
            document.getElementById("container")
        )
    </script>
</body>
</html>